package whisper.common.utils;

/**
 * Created by JT on 2017/12/9.
 */
public class MatchUtils {

    private static final String MATCH_ALL = "/**";

    public static boolean match(String str, String pattern) {
        if (pattern.equals(MATCH_ALL) || str.equals(pattern)) return true;

        if (pattern.endsWith(MATCH_ALL)) {
            if (str.contains(pattern.substring(0, pattern.length() - 3)))
                return true;
            else
                return str.matches(pattern.replace("**", ".*").replace("*", ".*"));
        } else {
            return str.matches(pattern.replace("**", ".*").replace("*", ".*"));
        }

    }
}
